import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter)
const originPush =  VueRouter.prototype.push
const originReplace = VueRouter.prototype.replace
VueRouter.prototype.push = function(obj,resolved,rejected) {
  if(resolved === undefined && rejected === undefined) {
    return originPush.call(this,obj).catch((err)=>{console.log(err.message)})
  }else {
    return originPush.call(this,obj,resolved,rejected)
  }
}
VueRouter.prototype.replace = function(obj,resolved,rejected) {
  if(resolved === undefined && rejected === undefined) {
    return originReplace.call(this,obj).catch(()=>{})
  }else {
    return originReplace.call(this,obj,resolved,rejected)
  }
}
const router = new VueRouter({
  mode: 'history',
  routes,
  scrollBehavior (to, from, savedPosition) {
    return { y: 0 }
  }
})
export default router